<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class del_sessionKeyModel{ 
    protected $CI;
    protected $timeoutminute = 1440; //默认24小时超时
    public function __construct(){
        $this->CI =& get_instance();
        $this->CI->load->database();
    }
    /**
     * [findByKey description]
     * @param  [type] $account  [description]
     * @param  [type] $password [description]
     * @return [type]           [description]
     */
    public function findByKey($key){
        $query = "SELECT * FROM session_key where session_key = $key order by id desc limit 1";
        $info = $this->CI->db->query($query);
        $object = $info->row();
        return $object;
    }

    /**
     * [延长登录时间，所有涉及到后台的操作，都会有]
     * @return [type] [description]
     */
    public function updateLoginDeadline($userid,$session_key,$session_key_value){
        // echo $userid,$session_key;exit;
        $timeoutminute = $this->timeoutminute;
        $session_key_value['deadlinetime'] = date("Y-m-d H:i:s",strtotime("+$timeoutminute  minute"));
        // var_dump($session_key_value);exit;
        $session_key_value = json_encode($session_key_value);
        $this->CI->session->$session_key = $session_key_value; 
        $query = "update session_key set session_key_value = '$session_key_value' where session_key = '$session_key'";
        $info = $this->CI->db->query($query);
        return 0;
    }
}